<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        const arr1 = [1, 2, 3, 4, 5];
        const arr2 = [6, 7, 8, 9];

        // 迭代器创建函数  iterator creator
        function createIterator(arr) {
            let i = 0;//当前的数组下标
            return { 
                next() {
                    var result = {
                        value: arr[i],
                        done: i >= arr.length
                    }
                    i++;
                    return result;
                }
            }
        }

        const iter1 = createIterator(arr1);
        const iter2 = createIterator(arr2);

    </script>
</body>

</html>